$().ready(function(){
    $("input.data").mask("99/99/9999");
    $("input.telefone").mask("(99) 9999-9999");
    $("input.cpf").mask("999.999.999-99");
    $("input.cnpj").mask("99.999.999/9999-99");
    $("input.cep").mask("99.999-999");

    $('input.valor').priceFormat({
        prefix: '',
        centsSeparator: ',',
        thousandsSeparator: '.'
    });

    $('.data').datepicker({
        changeMonth: true,
        changeYear: true,
        showOn: 'button',
        buttonImage: baseUrlTheme + '/img/calendar.gif',
        buttonImageOnly: true,
        regional: 'pt-BR'
    });

    $('#botao-cancelar').click(function(){
        window.location = $(this).attr('action');
    });

    $( ".accordion" ).accordion({
        autoHeight: false,
        collapsible: true,
        autoOpen: false
    });

    $( "#ev-div-dialog-modal" ).dialog({
        autoOpen: false,
        height: 140,
        modal: true
    });

    $( "#ev-div-dialog-form" ).dialog({
        autoOpen: false,
        title: this.title,
        height: 550,
        width: 750,
        modal: true,
        buttons: {
            "Salvar": function() {
                $("#ev-div-dialog-form form").submit();
                $( this ).dialog( "close" );
            },
            Cancelar: function() {
                $( this ).dialog( "close" );
            }
        },
        close: function() {
            $( this ).html("");
        }
    });

    $("a.ev-dialog-form").live("click", function () {
        var url    = this.href;
        var title  = this.title;
        var target = this.target;
        var urlAfterComplete = this.urlAfterComplete;
        var $dialogForm = $("#ev-div-dialog-form");

        $.get(url, {}, function(data, textStatus, jqXHR) {
            $dialogForm.html(data);
            $dialogForm.dialog("open");

            var options = {
                    success : function() {
                        $(target).load(urlAfterComplete);
                    }
            };
            //$(".ev-form-ajax").ajaxForm(options);
        });
        return false;
    });

});
